<?php
  class Plugins_Trip extends model {
  
  function getformadd($productid="")
  {
  $code  = '<form class="wrpCtcTripPlg">'."\n";
$code .= '<fieldset class="wrpCtcInfo">'."\n";
$code .= '<div class="wrpHdInfoGen mgBtm10">'."\n";
$code .= '<h2 class="fs04 clTxt2">Contact</h2>'."\n";
$code .= '<input type="checkbox" name="samecontactprofile[]" value="'.$this->userdata['userid'].'" id="cbCtc" class="checkBoxDm">'."\n";
$code .= '<label for="cbCtc" class="userSlctNone clTxt3 fs02">Same as your profile</label>'."\n";
$code .= '</div>'."\n";
$code .= '<table class="tbGenInfo tbAddCtnt clTxt3 fs03">'."\n";
$code .= '<tbody><tr>'."\n";
$code .= '<th>Facebook</th>'."\n";
$code .= '<td><input type="text" name="facebook[]" placeholder="e.g. facebook.com/dmconnex" class="clBg5 clBd2 fs03 clTxt2"></td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Twitter</th>'."\n";
$code .= '<td><input type="text" name="twitter[]" placeholder="e.g. twitter.com/dmconnex" class="clBg5 clBd2 fs03 clTxt2"></td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Google+</th>'."\n";
$code .= '<td><input type="text" name="googleplus[]"  placeholder="e.g. plus.google.com/+dmconnex" class="clBg5 clBd2 fs03 clTxt2"></td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Website</th>'."\n";
$code .= '<td><input type="text" name="website[]" class="clBg5 clBd2 fs03 clTxt2"></td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Email</th>'."\n";
$code .= '<td><input type="text" name="email[]" class="clBg5 clBd2 fs03 clTxt2"></td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Phone</th>'."\n";
$code .= '<td><input type="text" name="phone[]" class="clBg5 clBd2 fs03 clTxt2"></td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Fax</th>'."\n";
$code .= '<td><input type="text" name="fax[]" class="clBg5 clBd2 fs03 clTxt2"></td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>ETC</th>'."\n";
$code .= '<td><textarea placeholder="e.g. instragram@dmconnex" name="etc[]" class="clBg5 clBd2 fs03 clTxt2"></textarea></td>'."\n";
$code .= '</tr>'."\n";
$code .= '</tbody></table>'."\n";
$code .= '</fieldset>'."\n";
$code .= '</form>';
$arraydata['form']=addslashes(str_replace(array("\r", "", "\r"), '', $code));  
  return $arraydata; 
  
  }
  
  function saveplugin($arraydata,$productid,$plugreid)
  {
  
  $arraydata2=$arraydata;
  $arraydata2['productid']=$productid;
  $arraydata2['plugreid']=$plugreid;
  
 // if($arraydata['simgmid'])$arraydata['simgmid']=$this->swicthpathimage($arraydata['simgmid'],$productid);
//  if($arraydata['imgmid'])$arraydata['imgmid']=$this->swicthpathimage($arraydata['imgmid'],$productid);
  
  unset($arraydata2['objdata']); 
  
  $this->db->db_set($arraydata2,'tb_plugins_trip');
  $sql="delete from tb_plugins_poi where productid=".$productid;
  $this->db->db_delete($sql);
  if(count($arraydata['objdata']))
  {
  
  foreach($arraydata['objdata'] as $valuedata2)
  {
  
  if($valuedata2['photomain'])
  {
  $valuedata2['imgmid']= $this->savephotobase64($valuedata2['photomain']);
  $valuedata2['simgmid']=$valuedata2['imgmid'];
  unset($valuedata2['photomain']);
  }
  
  
   $valuedata2['productid']=$productid;
   if($valuedata2['simgmid'])$valuedata2['simgmid']=$this->swicthpathimage($valuedata2['simgmid'],$productid);
   if($valuedata2['imgmid'])$valuedata2['imgmid']=$this->swicthpathimage($valuedata2['imgmid'],$productid);
   $this->db->db_set($valuedata2,'tb_plugins_poi');
  
  
  }
  
  
  }
  
  }
  
  function getformlanding($arraydata)
  {
$code  = '<div class="wrpCtcInfo">'."\n";
$code .= '<div class="wrpHdInfoGen">'."\n";
$code .= '<h2 class="clTxt2 fs04">Contact</h2>'."\n";
$code .= '</div>'."\n";
$code .= '<table class="tbGenInfo tbCtcLd tbAddCtnt clTxt3 fs03">'."\n";
$code .= '<tbody>'."\n";

if(strpos($arraydata['facebook'],"facebook")!==false)
{
$datafacebook=$arraydata['facebook'];
if(strpos($arraydata['facebook'],"http://")!==false)
{
$datafacebook="http://".$arraydata['facebook'];

}


$code .= '<tr>';
$code .= '<th>Facebook</th>';
$code .= '<td><a href="'.$datafacebook.'" target="_blank">'.$datafacebook.'</a></td>';
$code .= '</tr>';
}
if(strpos($arraydata['twitter'],"twitter")!==false)
{
$datatwitter=$arraydata['twitter'];
if(strpos($arraydata['twitter'],"http://")!==false)
{
    $datatwitter="http://"+$arraydata['twitter'];

}
$code .= '<tr>';
$code .= '<th>Twitter</th>';
$code .= '<td><a href="'.$datatwitter.'" target="_blank">'.$datatwitter.'</a></td>';
$code .= '</tr>';
}
if(strpos($arraydata['googleplus'],"plus.google")!==false)
{
$datatgoogleplus=$arraydata['googleplus'];
if(strpos($arraydata['googleplus'],"http://")!==false)
{
    $datatgoogleplus="http://"+$arraydata['googleplus'];

}

$code .= '<tr>';
$code .= '<th>Google+</th>';
$code .= '<td><a href="'.$datatgoogleplus.'" target="_blank" >'.$datatgoogleplus.'</a></td>';
$code .= '</tr>';

}
if($arraydata['website'])
{

if(filter_var($arraydata['website'], FILTER_VALIDATE_URL) === FALSE)
{
$code .= '<tr>';
$code .= '<th>Website</th>';
$code .= '<td><a href="'.$arraydata['website'].'" target="_blank" >'.$arraydata['website'].'</a></td>';
$code .= '</tr>';
}
}
if($arraydata['email'])
{
if(filter_var($arraydata['email'], FILTER_VALIDATE_EMAIL))
{
$code .= '<tr>';
$code .= '<th>Email</th>';
$code .= '<td>'.$arraydata['email'].'</td>';
$code .= '</tr>';
}
}
if($arraydata['phone'])
{
$code .= '<tr>';
$code .= '<th>Phone</th>';
$code .= '<td>'.$arraydata['phone'].'</td>';
$code .= '</tr>';
}
if($arraydata['fax'])
{
$code .= '<tr>';
$code .= '<th>Fax</th>';
$code .= '<td>'.$arraydata['fax'].'</td>';
$code .= '</tr>';
}
if($arraydata['etc'])
{
$code .= '<tr>';
$code .= '<th>ETC</th>';
$code .= '<td>'.$arraydata['etc'].'</td>';
$code .= '</tr>';
}


$code .= '</tbody></table>'."\n";
$code .= '</div>';


$data['str']=$code;
$data['target']='firsttarget';


if(count($arraydata['objdata']))
{


$code="";
$code .= '<div class="ldIt wrpMapLd clBg4 w640 mapdataroute" >'."\n";
$code .= '<div class="icoDefLd">'."\n";
$code .= '<span class="ico icoMapDefLd"></span>'."\n";
$code .= '<span>Map</span>'."\n";
$code .= '</div>'."\n";
$code .= '</div>';
$rowdata=1;
$rowdata2=1;
 $rowset=0;
$alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
foreach($arraydata['objdata'] as $keydata=> $valueobjdata)
{

$code .= '<div class="ldIt wrpMyTripLd clBg4 w640 clearfix">'."\n";
$code .= '<div class="wrpAtcPlg">'."\n";
$code .= '<div class="spnHdDayTrip clTxtW">'."\n";
$code .= '<span class="fs03">Day '.$rowdata.'</span><br>'."\n";
$code .= '<span class="rcmAddGen fs01">'.$keydata.'</span>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPlgAreaTrip">'."\n";
$code .= '<div class="plgAreaTrip clearfix">'."\n";
 if(count($valueobjdata))
 {

 foreach($valueobjdata as $valuedata2)
 {
 if($valuedata2['isactivity'])
 {
$code .= '<div class="wrpInCell wrpInCellTrip w158 wrpActCell" style="margin:1px" onclick="popupactivites(\''.$valuedata2['title'].'\',\''.$valuedata2['description'].'\')">'."\n";
$code .= '<div class="ovlCellTrip w158"></div>'."\n";
$code .= '<a href="javascript:void(0)"  class="galleryimage"><img height="158" title="'.$valuedata2['img']['newpath'].'" width="158" alt="img" src="'.$valuedata2['simg']['newpath'].'" class="imgCell w158"></a>'."\n";
$code .= '<div class="ldTtlCell ldTtlTrip fs05 clTxtCell cutTxt">'.$valuedata2['title'].'</div>'."\n";
$code .= '<div class="timeTrip clTxtW fs01">'.date("h:i A",strtotime($valuedata2['plandate'])).'</div>'."\n";
$code .= '<div class="pointTrip">'."\n";
$code .= '<span class="clTxtW fs02">'.$rowdata2.'</span>'."\n";
$code .= '</div>'."\n";
$code .= '</div>';

$rowdata2++;
 
 }else
 {
 $lat="";
 $lng="";
 if(count($valuedata2['data']['plugins']))
 {
 foreach($valuedata2['data']['plugins'] as $valueplugins)
 {
 
 if($valueplugins['plugid']==5)
 {
 $lat=$valueplugins['lat'];
 $lng=$valueplugins['lng'];
 
 }
 
 }
 
 }
 
$code .= '<div class="wrpInCell wrpInCellTrip w158 pointTripData" onclick="linkto(\''.baseinfo.'/'.$valuedata2['data']['link'].'/'.$valuedata2['data']['productid'].'\')"  style="margin:1px">'."\n";
$code .= '<div class="ovlCellTrip w158"></div>'."\n";
$code .= '<a href="'.baseinfo.'/'.$valuedata2['data']['link'].'/'.$valuedata2['data']['productid'].'" target="_blank"><img height="158" width="158" alt="img" src="'.$valuedata2['data']['simg']['newpath'].'" class="imgCell w158"></a>'."\n";
$code .= '<div class="ldTtlCell ldTtlTrip fs05 clTxtCell cutTxt">'.$valuedata2['data']['title'].'</div>'."\n";
$code .= '<div class="timeTrip clTxtW fs01">'.date("h:i A",strtotime($valuedata2['plandate'])).'</div>'."\n";
$code .= '<div class="pointTrip">'."\n";
$code .= '<span class="clTxtW fs02">'.$alphabet[$rowset].'</span>'."\n";
$code .= '</div><input type="hidden" value="'.$lng.'" name="lngset[]"><input type="hidden" value="'.$lat.'" name="latset[]">'."\n";
$code .= '</div>';
$rowset++;
 
 }
 
 
 }
 }

$code .= '</div>'."\n";


$code .= '</div>'."\n";
$code .= '</div>';


$rowdata++;




}

$data['str2']=$code;
$data['target2']='secondtarget';


$data['script']="initmapdataroute();";


}





return $data;
  
  }
  
  function getplugin($plugreid)
  {
  $sql="select * from tb_plugins_trip where plugreid=".$plugreid;
  $arrayplugin=$this->db->db_set_1recordrow($sql);
 if($arrayplugin['samecontactprofile'])
  {
  $where=array();
  $select="facebook,twitter,googleplus,email,website,phone,fax,etc";
  $where['userid']=$arrayplugin['samecontactprofile'];
  $arrayplugin2= $this->getdatarow("tb_user",$select,$where,1);
  


  $arrayplugin['facebook']=$arrayplugin2['facebook'];
  $arrayplugin['twitter']=$arrayplugin2['twitter'];
  $arrayplugin['googleplus']=$arrayplugin2['googleplus'];
  $arrayplugin['email']=$arrayplugin2['email'];
  $arrayplugin['website']=$arrayplugin2['website'];
  $arrayplugin['phone']=$arrayplugin2['phone'];
  $arrayplugin['fax']=$arrayplugin2['fax'];
  $arrayplugin['etc']=$arrayplugin2['etc'];
  

  
  }
  
  $arrayplugin['objdata']=array();
  $arrayplugin['objdata2']=array();
  $sql="select *,DATE_FORMAT(tb_plugins_poi.plandate,'%h:%i %p') as plandate2  from tb_plugins_poi where productid=".$arrayplugin['productid'].' order by plandate asc';
  $arrayplugin3=$this->db->db_set_recordset($sql);
  $arraydatedata=array();
  $arraydatedata2=array();
  if(count($arrayplugin3)) 
  {
  

  foreach($arrayplugin3 as $valueplugin3)
  {
  //=$valueplugin3;
  
  if($valueplugin3['isactivity'])
  {
  $valueplugin3['img']= $this->getimagebyimgmid($valueplugin3['imgmid']);
  $valueplugin3['simg']= $this->getimagebyimgmid($valueplugin3['simgmid']);
  
  }else
  {
  
  $where=" where tb_product.productid=".$valueplugin3['sproductid'];
$arraydata5=$this->getproductbycondition($where,'','','','','',1);
  $valueplugin3['data']=$arraydata5[0];
  
  
  }
  
  if($valueplugin3['dateset'])
  {
  
  
  list($y,$m,$d)=explode("-",$valueplugin3['dateset']);
  $arraydatedata[$d.'/'.$m.'/'.$y][]=$valueplugin3;
  
  
  }
  
  
  
  
  }
  $arrayplugin['objdata']=$arraydatedata;
  
  if(count($arraydatedata))
  {
  foreach($arraydatedata as $keydatedata =>$valuedatedata)
  {
  
  $arrayplugin['objdata2'][]=array('date'=>$keydatedata,'data'=>$valuedatedata);
  
  }
  
  }
  
  
  }
  
  
 
  //$arrayplugin['img']= $this->getimagebyimgmid($arrayplugin['imgmid']);
 // $arrayplugin['simg']= $this->getimagebyimgmid($arrayplugin['simgmid']);
 


  
  return $arrayplugin;
  

  
  }
  
  }
?>
